package com.bluefox.modules.system.domain;

import com.bluefox.jpa.model.AbstractAuditModel;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;

/**
 * @CLassName Role
 * @Description TODO
 * @Author 孙峰
 * @Date 2020/1/1 18:00
 * @Version 1.0
 */
@Entity
@Getter
@Setter
@Table(name = "sys_role")
public class SysRole extends AbstractAuditModel implements Serializable {



    /**
     * 角色名称
     */
    @Column(name = "role_name", length = 64, nullable = false)
    private String roleName;

    /**
     * 角色权限字符串
     */
    @Column(name = "role_key", length = 100, nullable = false)
    private String roleKey;

    /**
     * 角色排序
     */
    @Column(name = "role_sort", nullable = false)
    private Integer roleSort;

    /**
     * 数据范围（1：所有数据权限；2：自定义数据权限；3：本部门数据权限；4：本部门及以下数据权限）
     */
    @Column(name = "data_scope", length = 1)
    private String dataScope;

    /**
     * 角色状态（0正常 1停用）
     */
    @Column(name = "status", length = 1, nullable = false)
    private String status = "0";

    /**
     * 删除标志（0代表存在 2代表删除）
     */
    @Column(name = "del_flag", length = 1)
    private String delFlag;



    @JsonIgnore
    @ManyToMany(mappedBy = "sysRoles")
    private Set<SysUser> sysUsers;

    @ManyToMany
    @JoinTable(name = "sys_roles_menus", joinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "menu_id", referencedColumnName = "id")})
    private Set<SysMenu> sysMenus;

    @ManyToMany
    @JoinTable(name = "sys_roles_depts", joinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "dept_id", referencedColumnName = "id")})
    private Set<SysDept> sysDepts;



    public @interface Update {
    }


}
